var open_id = "";
var openIdPath = 'http://mdl2.082818.com';
//var path = 'http://127.0.0.1:8020/jiaoyu/';
var path = "http://mdl1.082818.com/";
var apiPath = 'http://mdl2.082818.com/';
var filePath = 'http://mdl3.082818.com';
var days = 30;

function getData(key) {
	var arr, reg = new RegExp("(^| )" + key + "=([^;]*)(;|$)");
	if(arr = document.cookie.match(reg))
		return unescape(arr[2]);
	else return null;
}

function getOpenId() {
	if(GetQueryString('open_id')) {
		if(!localStorage.getItem('open_id')) {
			localStorage.setItem('open_id', GetQueryString('open_id'));
		}
	}
	if(!localStorage.getItem('open_id')) {
		var state = openIdPath + '/user/get-openid?referrer=' + encodeURIComponent(document.location.href);
		var url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx2eb6786a9f91c7df&redirect_uri=' +
			encodeURIComponent(state) + '&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
		window.location.href = url;
	} else {
		open_id = localStorage.getItem('open_id');
	}
}

//url?XX
function GetQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg); //search,查询？后面的参数，并匹配正则
	if(r != null) return unescape(r[2]);
	return null;
}

function saveData(key, value, days) {
	var exp = new Date();
	exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
	document.cookie = key + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path =" + "/";
}

function uuid() {
	var s = [];
	var hexDigits = "0123456789abcdef";
	for(var i = 0; i < 36; i++) {
		s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
	}
	s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
	s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
	s[8] = s[13] = s[18] = s[23] = "-";

	var uuid = s.join("");
	return uuid;
}
// 兼容Android 键盘弹起时,影响布局
var h = document.body.scrollHeight // 用onresize事件监控窗口或框架被调整大小，先把一开始的高度记录下来
window.onresize = function() { // 如果当前窗口小于一开始记录的窗口高度，那就让当前窗口等于一开始窗口的高度
	if(document.body.scrollHeight < h) {
		document.body.style.height = h + "px"
	}
}

function getBase64Image(img) {
	var canvas = document.createElement("canvas");
	canvas.width = img.width;
	canvas.height = img.height;
	var ctx = canvas.getContext("2d");
	ctx.drawImage(img, 0, 0, img.width, img.height);
	var ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase();
	var dataURL = canvas.toDataURL("image/" + ext);
	return dataURL;
}